home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / S / sfCL Update.cpt / sfCL Update / CLottoConfigure.p < prev    next >
Encoding:
Text File  |  1990-10-22  |  11.6 KB  |  266 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CLottoConfigure.p                                                                    }
  4. {}
  5. {}
  6. {        Copyright © 1990, Stanley Fertig.  All rights reserved.            }
  7. {}
  8. {****************************************************}
  9.  
  10.  
  11. unit CLottoConfigure;      {Dialog objects to enable user to configure the choices of Lotto numbers.}
  12.  
  13. interface
  14.     uses
  15.         TCL, sfCL, LottoIntf;
  16. {----------------------------------------------------------------------------}
  17.  
  18. implementation
  19.  
  20.     procedure CLottoConfigure.ILottoConfigure;             {Initialize director for nonmodal Dialog}
  21.         var
  22.             aDial: CLottoConfigureDial;
  23.     begin
  24.         IDirector(gApplication);                                    {Be sure to call the default method first}
  25.  
  26.         new(aDial);                                                    {Create & initialize dialog window object}
  27.         itsWindow := aDial;
  28.         aDial.IDialog(integer(cmdConfigure), false, gDesktop, Self, false, true);
  29.  
  30.         itsGopher := Self;
  31.         gGopher := itsGopher;
  32.         CLottoDoc(gDocument).fConfigure := Self                    {Tell Lotto document we exist}
  33.     end;
  34. {----------------------------------------------------------------------------}
  35.  
  36.     procedure CLottoConfigure.Free;
  37.     begin
  38.         CLottoDoc(gDocument).fConfigure := nil;  {Before we disappear, warn the Lotto Document about it}
  39.         inherited Free
  40.     end;
  41. {----------------------------------------------------------------------------}
  42.  
  43.     procedure CLottoConfigure.Dawdle (var maxSleep: longint);   {Blink cursor at insertion point if needed}
  44.     begin
  45.         if not gInBackground & (CLottoConfigureDial(itsWindow).macPort = FrontWindow) & (DialogPeek(CLottoConfigureDial(itsWindow).macPort)^.editField > -1) then
  46.             begin
  47.                 TEIdle(DialogPeek(CLottoConfigureDial(itsWindow).macPort)^.textH);
  48.                 maxSleep := GetCaretTime
  49.             end
  50.     end;
  51. {----------------------------------------------------------------------------}
  52.  
  53.     procedure CLottoConfigure.UpdateMenus;
  54.         var
  55.             i: shortint;
  56.             FontMenu: MenuHandle;
  57.     begin
  58.         inherited UpdateMenus;                         {Do standard menu updates}
  59.         FontMenu := GetMHandle(MenuFont);         {Get handle to Font menu}
  60.  
  61.         CDialog(Self.itsWindow).UpdateEdit;           {Update Edit menu items accordingly}
  62.         if not gInBackground then
  63.             gBartender.EnableCmd(cmdHelp);              {enable the Help menu command}
  64.  
  65.         gBartender.DisableCmd(cmdConfigure);            {Disable commands which are meaningless}
  66.         gBartender.DisableCmd(cmdNew);                    {if Configure dialog is topmost.}
  67.         gBartender.DisableCmd(cmdPageSetup);
  68.         gBartender.DisableCmd(cmdPrint);
  69.  
  70.         gBartender.DisableCmd(cmdFontSizeDial);
  71.         for i := 1 to CountMItems(FontMenu) do          {Disable all font items on Font menu}
  72.             DisableItem(FontMenu, i)
  73.     end;
  74. {----------------------------------------------------------------------------}
  75.  
  76.     procedure CLottoConfigureDial.IDialog (DIALid: integer; {Initialize the Dialog window object}
  77.                                     aFloating: Boolean; anEnclosure: CDesktop; aSupervisor: CBureaucrat; Beep, DoCenter: boolean);
  78.         const
  79.             UserNumber = 2;            {ID# for userItem for highlighting default OK box}
  80.             UniverseNumber = 4;       {Textbox for number of potential numbers to choose from}
  81.             ChoiceNumber = 5;          {Textbox for number of numbers to choose}
  82.             checkBoxNumber = 6;     {Checkbox for choosing numbers With or Without Replacement}
  83.         var
  84.             aUniverse, aNumbChoices: str255;
  85.             theType: integer;
  86.             theItemHandle: Handle;
  87.             theBox: Rect;
  88.             theCheckBox: ControlHandle;
  89.     begin
  90.         inherited IDialog(DIALid, aFloating, anEnclosure, aSupervisor, Beep, DoCenter);  {standard Dialog window initialize}
  91.  
  92.         aUniverse := stringof(CLottoDoc(gDocument).fUniverse : 1);   {Initialize universe to Lotto's existing universe of numbers.}
  93.         aNumbChoices := stringof(CLottoDoc(gDocument).fNumbChoices : 1); {Initialize # of choices to Lotto's existing # of choices.}
  94.  
  95.         GetDItem(Self.macPort, UserNumber, theType, theItemHandle, theBox);    {Get handle to OK button}
  96.         SetDItem(Self.macPort, UserNumber, theType, @SelectButton, theBox);   {Hilite OK button via userItem}
  97.  
  98.         GetDItem(Self.macPort, UniverseNumber, theType, theItemHandle, theBox);
  99.         SetIText(theitemHandle, aUniverse);                         {Put universe in appropriate textbox}
  100.  
  101.         GetDItem(Self.macPort, ChoiceNumber, theType, theItemHandle, theBox);
  102.         SetIText(theitemHandle, aNumbChoices);                                {Put # choices in appropriate textbox}
  103.         SelIText(Self.macPort, ChoiceNumber, kSelStart, kSelEnd);    {Select this text to start}
  104.  
  105.         GetDItem(Self.macPort, checkBoxNumber, theType, theItemHandle, theBox);  {Get handle to checkbox}
  106.         theCheckBox := ControlHandle(theitemHandle);                                               {Convert to Control Handle}
  107.         if CLottoDoc(gDocument).fWithReplacement then     {Check or uncheck box, as per existing Lotto setting}
  108.             SetCtlValue(theCheckBox, 1)
  109.         else
  110.             SetCtlValue(theCheckBox, 0);
  111.         Self.Select                                     {Activate the Dialog box object on the screen}
  112.     end;
  113. {----------------------------------------------------------------------------}
  114.  
  115.     function CLottoConfigureDial.Filter (thedial: DialogPtr; var anEvent: EventRecord; var itemNumber: integer): boolean;
  116.         var
  117.             chCode: integer;
  118.             ch: char;
  119.             cmdDown: boolean;
  120.     begin
  121.         if anEvent.what in [keydown, AutoKey] then
  122.             begin
  123.                 Filter := true;
  124.                 with anEvent do
  125.                     begin
  126.                         chCode := BitAnd(message, CharCodeMask);
  127.                         ch := chr(chCode);
  128.                         cmdDown := (BitAnd(modifiers, CmdKey) <> 0)
  129.                     end;
  130.  
  131.                 if not cmdDown then
  132.                     begin
  133.                         if (chCode in [$8, $9, $3, $D, $30..$39]) then         {List your 'Acceptable' keys here}
  134.                             Filter := inherited Filter(thedial, anEvent, itemNumber)
  135.                         else
  136.                             begin
  137.                                 Sysbeep(1);
  138.                                 itemNumber := 0;
  139.                             end
  140.                     end
  141.                 else  {if Command Key is down}
  142.                     Filter := inherited Filter(thedial, anEvent, itemNumber)
  143.             end
  144.         else  {if not Keyboard Event}
  145.             Filter := inherited Filter(thedial, anEvent, itemNumber)
  146.     end;
  147. {----------------------------------------------------------------------------}
  148.  
  149.     procedure CLottoConfigureDial.DoDialog (anEvent: EventRecord);  {After dialog box on screen, respond to User actions}
  150.         const
  151.             checkBoxNumber = 6;
  152.             cancelNumber = 3;
  153.         var
  154.             theItem: integer;
  155.             FiltItemNumber: integer;
  156.             theCheckBox: ControlHandle;
  157.             theItemHandle: Handle;
  158.             theType: integer;
  159.             theBox: Rect;
  160.             oldValue: integer;
  161.             theString: str255;
  162.             dPtr: DialogPtr;
  163.             FilterResult: boolean;
  164.     begin
  165.         Prepare;                           {Set port & Clipping to our dialog box}
  166.         theItem := 0;                    {Initialize to no User action}
  167.         FilterResult := false;         {Initialize to no keyboard action}
  168.  
  169.         GetDItem(Self.macPort, checkBoxNumber, theType, theItemHandle, theBox); {Get handle to Checkbox}
  170.         theCheckBox := ControlHandle(theitemHandle);                                              {Convert to Control Handle}
  171.  
  172.         if anEvent.what in [Keydown, AutoKey] then                          {User typed something?}
  173.             begin
  174.                 dPtr := Self.macPort;                                                        {Need DialogPtr for Filter functions.}
  175.                 FilterResult := Self.Filter(dPtr, anEvent, FiltItemNumber)  {Filter function for special keyboard items}
  176.             end;
  177.  
  178.         if FilterResult then    {Filter returned positive result, i.e. meaningful keyboard entry}
  179.             case FiltItemNumber of     {Which keyboard command did User type?}
  180.  
  181.                 AltcmdQuit:                                            {User typed Command-Q}
  182.                     gApplication.DoCommand(cmdQuit);      {Let's quit the Application.}
  183.  
  184.                 cmdHelp:                                               {User hit 'Help' key on Ext. keyboard, or Command-H}
  185.                     gApplication.DoCommand(FiltItemNumber);  {Bring up 'Help' Dialog.}
  186.  
  187.                 cancelNumber:                                       {User hit 'escape' button}
  188.                     Self.Close;                                            {Close dialog box and kill this object}
  189.  
  190.                 OK:                                                                             {User hit 'Enter' or 'Return}
  191.                     begin
  192.                         GetDItem(Self.macPort, 4, theType, theItemHandle, theBox);   {Get handle to textbox}
  193.                         GetIText(theitemHandle, theString);                                         {Get text from textbox}
  194.                         oldValue := IntVal(theString);                                                   {Convert string to integer}
  195.                         if oldValue in [1..maxChoices] then                                       {Is integer acceptable?}
  196.                             CLottoDoc(gDocument).fUniverse := oldValue                         {Set universe size to integer}
  197.                         else
  198.                             Sysbeep(1);
  199.  
  200.                         GetDItem(Self.macPort, 5, theType, theItemHandle, theBox);   {Get handle to textbox}
  201.                         GetIText(theitemHandle, theString);                                         {Get text from textbox}
  202.                         oldValue := IntVal(theString);                                                   {Convert string to integer}
  203.                         if oldValue in [1..CLottoDoc(gDocument).fUniverse] then         {Is integer acceptable?}
  204.                             CLottoDoc(gDocument).fNumbChoices := oldValue                    {Set # choices to integer}
  205.                         else
  206.                             Sysbeep(1);
  207.  
  208.                         CLottoDoc(gDocument).fWithReplacement := GetCtlValue(theCheckBox) = 1;   {Set Lotto's replacement option based on whether option checked}
  209.                         Self.Close         {Close dialog box and kill this object}
  210.                     end;
  211.  
  212.                 otherwise
  213.             end                              {of Case}
  214.         else                                {Filter returned negative result, i.e. no acceptable key entry}
  215.             begin
  216.                 if anEvent.what = UpDateEvt then
  217.                     Self.Update                                                    {Update dialog box if necessary.}
  218.  
  219.                 else if anEvent.what = ActivateEvt then
  220.                     if BitAnd(anEvent.modifiers, ActiveFlag) = 1 then   {Activate dialog box or deactivate if need be}
  221.                         Self.Activate
  222.                     else
  223.                         Self.Deactivate
  224.  
  225.                 else if DialogSelect(anEvent, dPtr, theItem) then   {User clicked in enabled Item?}
  226.  
  227.                     case theItem of
  228.  
  229.                         cancelNumber:     {User clicked in Cancel button}
  230.                             Self.Close;         {Close dialog box and kill this object}
  231.  
  232.                         OK:                     {User clicked in OK button}
  233.                             begin
  234.                                 GetDItem(Self.macPort, 4, theType, theItemHandle, theBox); {Get handle to textbox}
  235.                                 GetIText(theitemHandle, theString);                                       {Get text from textbox}
  236.                                 oldValue := IntVal(theString);                                                 {Convert string to integer}
  237.                                 if oldValue in [1..maxChoices] then                                     {Is integer acceptable?}
  238.                                     CLottoDoc(gDocument).fUniverse := oldValue                        {Set universe size to integer}
  239.                                 else
  240.                                     Sysbeep(1);
  241.  
  242.                                 GetDItem(Self.macPort, 5, theType, theItemHandle, theBox);     {Get handle to textbox}
  243.                                 GetIText(theitemHandle, theString);                                           {Get text from textbox}
  244.                                 oldValue := IntVal(theString);                                                     {Convert string to integer}
  245.                                 if oldValue in [1..CLottoDoc(gDocument).fUniverse] then           {Is integer acceptable?}
  246.                                     CLottoDoc(gDocument).fNumbChoices := oldValue                      {Set # choices to integer}
  247.                                 else
  248.                                     Sysbeep(1);
  249.  
  250.                                 CLottoDoc(gDocument).fWithReplacement := GetCtlValue(theCheckBox) = 1;  {Set Lotto's replacement option based on whether option checked}
  251.                                 Self.Close                                                                     {Close dialog box and kill this object}
  252.                             end;
  253.  
  254.                         checkBoxNumber:                  {User clicked in Checkbox}
  255.                             begin
  256.                                 oldValue := GetCtlValue(theCheckBox);   {Get Checkbox value before Click}
  257.                                 SetCtlValue(theCheckBox, 1 - oldValue)  {Toggle to other value}
  258.                             end;
  259.  
  260.                         otherwise
  261.                     end {of CASE}
  262.             end
  263.     end;
  264. {----------------------------------------------------------------------------}
  265.  
  266. end.